/**
 * [101] 对称二叉树
 *
 * @format
 * @lc app=leetcode.cn id=101 lang=javascript
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isSymmetric = function (root) {
    if (root.left == null && root.right == null) return true
    if (!(root.left && root.right) || root.left.val !== root.right.val) return false
    function isSymmetry(p, q) {
        if (p == q && q == null) return true
        if (!(p && q) || p.val !== q.val) return false
        return isSymmetry(p.left, q.right) && isSymmetry(p.right, q.left)
    }
    return isSymmetry(root.left, root.right)
}
// @lc code=end
